/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package checador;


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

/**
 *
 * @author lynx
 */
public class Empleado{
    public static String nombreEmpleado;
  
    public  String  buscar(String ID){
         int temp;
        try{
                File fXmlFile = new File("datos.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);
		doc.getDocumentElement().normalize();
                
                NodeList nList = doc.getElementsByTagName("Empleado");
                
                for(temp = 0; temp < nList.getLength(); temp++){
                    
                    Node nNode = nList.item(temp); 
                    
                    if(nNode.getLocalName()== ID){
                             
                        Element eElement = (Element) nNode;
                        
                        nombreEmpleado = getTagValue("Nombre", eElement)+" "+getTagValue("ApellidoP",eElement)+" "+ getTagValue("ApellidoM", eElement);
                    }
                
                }
            
                
                if (temp == nList.getLength()){
                
                      nombreEmpleado= "No existe ese empleado";
                      
                
                }
                
                
                
        }
        catch(Exception e){
            e.printStackTrace();
        }
        
           
        
        
    return nombreEmpleado;
    
    }
    
    private static String getTagValue(String sTag, Element eElement) {
	NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
 
        Node nValue = (Node) nlList.item(0);
 
	return nValue.getNodeValue();
  }

    
    
    
    
    
}
